pub struct Solution;

impl Solution {
    pub fn reverse_bits(x: u32) -> u32 {
        let mut vec1 = Vec::new();
        let mut tmp = x;
        while tmp != 0 {
            let i = tmp & 1;
            vec1.push(i);
            tmp = tmp >> 1;
        }
        while vec1.len() < 32 {
            vec1.push(0);
        }
        vec1.iter().fold(0, |mut acc, &x| {
            acc = acc << 1;
            acc += x;
            return acc
        })
    }


    pub fn reverse_bits1(x: u32) -> u32 {
        let mut bits = vec![];
        let mut x = x;
        while x > 0 {
            bits.push(x & 1);
            x = x >> 1;
        }
        while bits.len() < 32 {
            bits.push(0);
        }
        // let mut res = 0;
        // for bit in bits {
        //     res = res * 2 + bit;
        // }
        // res
        bits.iter().fold(0, |acc, &b| acc * 2 + b)
    }
}